@extends("admin.layout.main")

@section("content")
<style>
    .orderDetal{
        width:90%;
        margin:0 auto;
    }
</style>
<div class="page-header">
    <h1>
        商品订单详情
    </h1>
</div>
<!-- div.table-responsive -->

<!-- div.dataTables_borderWrap -->
<div>
    <form class="form-horizontal" id="form" action="{{ route('admin.order.ajaxSave') }}" method="post">
        <input type="hidden" name="id" value="{{ $data->id }}">
        <input type="hidden" name="status" value="{{ $data->status+1 }}">
        <div class="orderDetal">
            <table id="simple" class="table  table-bordered table-hover">
                <thead>
                <tr>
                    <th colspan="4" style="border-right-color: #ddd;text-align: left;">基本信息</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td style="width: 15%;text-align: right">供应商：</td>
                    <td style="width: 35%;text-align:left;">创客中心</td>
                    <td style="width: 15%;text-align: right">订单编号：</td>
                    <td style="text-align:left;">{{ $data->order_sn }}</td>
                </tr>
                <tr>
                    <td style="width: 15%;text-align: right">订单状态：</td>
                    <td style="width: 35%;text-align:left;">{{ $statusArr[$data->status] }}</td>
                    <td style="width: 15%;text-align: right">下单时间：</td>
                    <td style="text-align:left;">{{ $data->created_at }}</td>
                </tr>
                <tr>
                    <td style="width: 15%;text-align: right">支付方式：</td>
                    <td style="width: 35%;text-align:left;">@if($data->finance)@if($data->finance->pay['payment_type']==0) 积分 @elseif($data->finance->pay['payment_type']==1) 微信 @else 支付宝 @endif @endif</td>
                    <td style="width: 15%;text-align: right">支付时间：</td>
                    <td style="text-align:left;">{{ $data->pay_time }}</td>
                </tr>
                </tbody>
            </table>
        </div>
        <div class="orderDetal">
            <table id="simple-table" class="table  table-bordered table-hover">
                <thead>
                <tr>
                    <th colspan="4" style="border-right-color: #ddd;text-align: left;">收货信息</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td style="width: 15%;text-align: right">收货人：</td>
                    <td style="width: 35%;text-align:left;">{{ $data->consignee }}</td>
                    <td style="width: 15%;text-align: right">联系电话：</td>
                    <td style="text-align:left;">{{ $data->mobile }}</td>
                </tr>
                <tr>
                    <td style="width: 15%;text-align: right">收货地址：</td>
                    <td style="width: 35%;text-align: left" colspan="3">{{ $data->address }}</td>
                </tr>
                <tr>
                    <td style="width: 15%;text-align: right">客户留言：</td>
                    <td style="width: 35%;text-align: left" colspan="3">{{ $data->user_message }}</td>
                </tr>
                </tbody>
            </table>
        </div>
        <div class="orderDetal">
            <table class="table  table-bordered table-hover">
                <thead>
                <tr>
                    <th style="border-right-color: #ddd;text-align: left;" colspan="4">
                        费用信息
                    </th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td style="width: 15%;text-align: right">小计：</td>
                    <td style="width: 35%;text-align:left;">{{ $data->order_amount }}</td>
                    <td style="width: 15%;text-align: right">购物券抵扣：</td>
                    <td style="text-align:left;">0.00</td>
                </tr>
                <tr>
                    <td style="width: 15%;text-align: right">应付：</td>
                    <td style="width: 35%;text-align: left" colspan="3">{{ $data->order_amount }}</td>
                </tr>
                </tbody>
            </table>
        </div>
        <div class="orderDetal">
            <table id="goodsList" class="table  table-bordered table-hover">
                <thead>
                <tr>
                    <th colspan="7" style="border-right-color: #ddd; line-height: 40px;text-align: left;">
                        商品信息
                    </th>
                </tr>
                <tr>
                    <th>商品编号</th>
                    <th>商品名称</th>
                    <th>单价</th>
                    <th>购买数量</th>
                    <th>小计</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data->orderGoods as $v)
                <tr>
                    <td>{{ $v->goods['name'] }}</td>
                    <td>{{ $v->goods['name'] }}</td>
                    <td>{{ $v->goods['member_price'] }}</td>
                    <td>{{ $v->goods_num }}</td>
                    <td class="price">{{ $v->member_price }}</td>
                </tr>
                @endforeach
                <tr>
                    <td colspan="4" style="text-align: right;">合计</td>
                    <td id="goods_price"></td>
                </tr>
                </tbody>
            </table>
        </div>
        @if($data->status > 1)
        <div class="orderDetal">
            <table class="table  table-bordered table-hover">
                <thead>
                <tr>
                    <th style="border-right-color: #ddd;text-align: left;" colspan="4">
                        订单操作
                    </th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    @if($data->status ==2)
                    <td>
                        <div>
                            物流公司：
                            <select name="shipping_name" id="">
                                <option value="0">选择物流公司</option>
                                @foreach($list as $v)
                                <option value="{{ $v->name }}">{{ $v->name }}</option>
                                @endforeach
                            </select>
                        </div>
                        <div style="margin-top: 10px">
                            物流单号：
                            <input type="text" name="shipping_code">
                        </div>
                    </td>
                    @endif
                    @if($data->status ==3 || $data->status == 4)
                        <td>
                            <div>
                                物流公司：
                                {{ $data->shipping_name }}
                            </div>
                            <div style="margin-top: 10px">
                                物流单号：
                                {{ $data->shipping_code }}
                            </div>
                            <div style="margin-top: 10px">
                                发货时间：
                                {{ $data->shipping_time }}
                            </div>
                        </td>
                    @endif
                    @if($data->status == 5)
                        <td>
                            <div>
                                取消原因：
                                {{ $data->admin_message }}
                            </div>
                            <div style="margin-top: 10px">
                                取消时间：
                                {{ $data->updated_at }}
                            </div>
                        </td>
                    @endif
                </tr>
                </tbody>
            </table>
        </div>
        @endif
        <div class="clearfix form-actions">
            <div class="col-md-offset-3 col-md-9">
                @if($data->status==2)
                <button class="btn btn-info sb" type="submit">
                    <i class="ace-icon fa fa-check bigger-110"></i>
                        确认发货
                </button>
                @endif
                @if($data->status==1 || $data->status==2)
                <a class="btn" href="javascript:;" onclick="cancel_order()">
                    <i class="ace-icon fa fa-undo bigger-110"></i>
                    取消订单
                </a>
                @endif
            </div>
        </div>
    </form>
</div>
<div class="bootbox modal fade bootbox-prompt in" id="check-remark" tabindex="-1" role="dialog" style="display: none;margin-top:15%">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="bootbox-close-button close" onclick="cancel_check()">×</button>
                <h4 class="modal-title">备注</h4>
            </div>
            <div class="modal-body">
                <div class="bootbox-body">
                    <form class="bootbox-form">
                        <input class="bootbox-input bootbox-input-text form-control" autocomplete="off" required type="text" id="remark">
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button data-bb-handler="confirm" type="button" class="btn btn-primary" onclick="confirm_check()">确认</button>
                <button data-bb-handler="cancel" type="button" class="btn btn-default" onclick="cancel_check()">取消</button>
            </div>
        </div>
    </div>
</div>
<script src="{{ config('global.assets_path') }}js/jquery.validate.min.js"></script>
<script src="{{ config('global.assets_path') }}js/messages_zh.js"></script>
<script src="/plugins/layui/layui.js"></script>
<script src="/plugins/layui/layui_component.js"></script>
<script src="/js/ajax.js"></script>
<script>
    $(function () {
       var good_prices = $('.price');
       var price = 0;
        $.each(good_prices, function (i, item) {
           price += Number($(this).html());
        })
       $('#goods_price').html(price.toFixed(2));
    });
    function cancel_order() {
        $('#check-remark').show();
    }
    function cancel_check() {
        $('#remark').val('');
        $('#check-remark').hide();
    }
    function confirm_check() {
        var remark = $('#remark').val();
        if(!remark){
            showMessage('未填写取消原因！',0);
            return false;
        }
        var id = $('input[name="id"]').val();
        $('#remark').val('');
        $('#check-remark').hide();
        var data = {'id':id,'status':5,'remark':remark};
        var url = '{{ route('admin.order.ajaxSave') }}';
        ajaxRequest(data,url,'post');
    }
</script>
@endsection